<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<link rel="stylesheet" type="text/css" href="../../css/public.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/login.css"/>
	</head>
	<body>
		<!-------------------reg-------------------------->
		<div class="reg">
			<form id="form-reg" action="#" method="post">
				<h1><a href="index"><img src="../../img/temp/logo2.png"></a></h1>
				<p>用户注册</p>
				<p><input type="text" name="username" value="" placeholder="请输入账号"></p>
				<p><input type="text"  name="password" value="" placeholder="请输入密码"></p>
				<p><input type="text"  name="" value="" placeholder="请确认密码"></p>
				<p class="txtL txt"><input class="code" type="text" name="" value="" placeholder="验证码"><img src="../../img/temp/code.jpg"></p>
				<p><input type="button" id="btn-reg" name="" value="注册"></p>
				<p class="txtL txt">完成此注册，即表明您同意了我们的<a href="#"><使用条款和隐私策略></使用条款和隐私策略></a></p>
				<p class="txt"><a href="login"><span></span>已有账号登录</a></p>
				<!--<a href="#" class="off"><img src="img/temp/off.png"></a>-->
			</form>
		</div>
	</body>
	<script type="text/javascript" src="../../js/jquery-3.5.1.min.js"></script>
	<script type="text/javascript" src="../../js/sweetalert.min.js"></script>
	<script type="text/javascript">
		$("#btn-reg").click(function() {
			$.ajax({
				url: "/register",
				type: "POST",
				data: $("#form-reg").serialize(),
				dataType: "json",
				success: function(json) {
					if (json.state == 200) {
						// alert("注册成功！");
						swal({
							title: '注册成功',
							icon: 'success'
						}).then(function () {
							location.href = 'login'
						})
						// location.href = "login.html";
					} else {
						// alert("注册失败！" + json.message);
						swal({
							title: '注册失败',
							icon: 'warning',
							text: json.message,
							button: {
								text: "确认",
								value: true,
							}
						}).then(function (isok) {
							if (isok) {
								location.href = 'reg'
							}
						})
					}
				}
			});
		});
	</script>
</html>
